package jltx.fragmentpageframework.simple.fragment.home;


import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import cn.jltx.support.SupportFragment;
import cn.jltx.utils.ViewHelper;
import cn.jltx.utils.XqLog;
import jltx.fragmentpageframework.R;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2016年01月29日.
 */
public class FragmentTAB2 extends SupportFragment {

    private final String TAG = FragmentTAB2.class.getSimpleName();


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        XqLog.d(TAG,TAG+".onCreate");
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        XqLog.d(TAG,TAG+".onAttach");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        XqLog.d(TAG,TAG+".onCreateView");
        return inflater.inflate(R.layout.fragment_simple_tab2, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        XqLog.d(TAG,TAG+".onViewCreated");
        assignViews(view);
        tv.setText(this.getClass().getSimpleName());
        btnPush.setOnClickListener(myOnClickListener);
        btnPop.setOnClickListener(myOnClickListener);
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        XqLog.d(TAG,TAG+".onActivityCreated");
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onResume() {
        XqLog.d(TAG,TAG+".onResume");
        super.onResume();
    }

    @Override
    public void onPause() {
        XqLog.d(TAG,TAG+".onPause");
        super.onPause();
    }

    @Override
    public void onStop() {
        XqLog.d(TAG,TAG+".onStop");
        super.onStop();
    }

    @Override
    public void onDetach() {
        XqLog.d(TAG,TAG+".onDetach");
        super.onDetach();
    }

    @Override
    public void onDestroyView() {
        XqLog.d(TAG,TAG+".onDestroyView");
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        XqLog.d(TAG,TAG+".onDestroy");
        super.onDestroy();
    }

    private TextView tv;
    private Button btnPop;
    private Button btnPush;

    private void assignViews(View view) {
        btnPop = (Button) view.findViewById(R.id.btn_pop);
        btnPush = (Button) view.findViewById(R.id.btn_push);
        tv = ViewHelper.findViewById(view,R.id.tv);
    }

    private View.OnClickListener myOnClickListener = new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.btn_pop:
                    getActivity().onBackPressed();
                    break;
                case R.id.btn_push:
                    FragmentTAB3 fragmentTAB3 = new FragmentTAB3();
//                    startFragment(fragmentTAB3);
                    startFragmentWithPop(fragmentTAB3);
                    break;
                default:
                    break;
            }
        }
    };

    @Override
    public boolean onBackPressedSupport() {
        return false;
    }
}
